﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CDSBDemandControlService;

namespace CDSBDemandControl.Presenter
{
    public class DemandModelTranslator
    {
        public static List<DemandModel> Translate(DemandCollection demandCollection)
        {
            List<DemandModel> DemandModelList = new List<DemandModel>();
            
            foreach (ServiceDemandModel serviceDemandModel in demandCollection)
            {
                DemandModel demandModel = new DemandModel();

                demandModel.ID = serviceDemandModel.ID;
                demandModel.Title = serviceDemandModel.Title;
                demandModel.State = serviceDemandModel.State;
                demandModel.WorkItemType = serviceDemandModel.WorkItemType;
                demandModel.Project = serviceDemandModel.Project;
                demandModel.Reason = serviceDemandModel.Reason;
                demandModel.CreatedBy = serviceDemandModel.CreatedBy;
                demandModel.AssignedTo = serviceDemandModel.AssignedTo;
                demandModel.EstimatedHours = serviceDemandModel.EstimatedHours;
                demandModel.EstimatedStart = serviceDemandModel.EstimatedStart != DateTime.MinValue ? (DateTime?)serviceDemandModel.EstimatedStart : null;
                demandModel.EstimatedConclude = serviceDemandModel.EstimatedConclude != DateTime.MinValue ? (DateTime?)serviceDemandModel.EstimatedConclude : null;
                demandModel.Start = serviceDemandModel.Start != DateTime.MinValue ? (DateTime?)serviceDemandModel.Start : null;
                demandModel.Conclude = serviceDemandModel.Conclude != DateTime.MinValue ? (DateTime?)serviceDemandModel.Conclude : null;

                DemandModelList.Add(demandModel);
            }

            return DemandModelList;
        }
    }
}